﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using Shanfree.Framework.Utility;
using Shanfree.SharpMovie.BLL;
using Shanfree.SharpMovie.Model;

public partial class List_Browse : BasePage
{
    /// <summary>
    /// 列表的主键
    /// </summary>
    public string ListID
    {
        get
        {
            return GetViewState("ListID");
        }
        set
        {
            ViewState["ListID"] = value;
        }
    }
    /// <summary>
    /// 不需要后台登陆
    /// </summary>
    protected override bool IsAuth
    {
        get
        {
            return false;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                string listID = GetRequest("listid");
                if (string.IsNullOrEmpty(listID))
                {
                    ShowMsg("未指定收藏分类。");
                }
                else
                {
                    // 编辑
                    this.ListID = listID;
                    ListInfo lInfo = new List().GetByID(listID);
                    if (lInfo == null)
                    {
                        ShowMsg("指定收藏分类不存在。");
                    }
                    lbListName.Text = lInfo.Name;
                    lbListRemark.Text = lInfo.Remark;
                    lbAmount.Text = lInfo.Amount.ToString();
                    lbAuthor.Text = lInfo.UserName;
                    lbCreateTime.Text = lInfo.CreateTime.ToShortDateString();
                    lbMenu.Text = lInfo.CatalogName;
                    BindList();
                }
            }
        }
        catch (Exception ex)
        {
            ShowMsg(ex.Message);
            LogEntry.Log.Write(ex.ToString(), EventLogEntryType.Error, LogSourceType.一般错误);
        }
    }
    private void BindList()
    {
        string listID = this.ListID;
        int pageSize = pGrid.PageSize;
        int pageIndex = pGrid.CurrentPageIndex;
        IList<ListItemInfo> itemList = new List().GetItemList(listID, pageSize, pageIndex);
        CustomList<ListItemInfo> cList = itemList as CustomList<ListItemInfo>;
        pGrid.TotalAmout = cList.TotalAmout;
        gvList.DataSource = cList;
        gvList.DataBind();
    }
    protected void pGrid_OnClick(object sender, EventArgs e)
    {
        try
        {
            BindList();
        }
        catch (Exception exc)
        {
            ShowMsg(exc.Message);
            LogEntry.Log.Write(exc.ToString(), EventLogEntryType.Error, LogSourceType.一般错误);
        }
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        Response.Redirect("Edit.aspx?id=" + this.ListID, false);
    }
}
